// 积分商品分类
// import { isEmpty } from 'lodash'
import * as types from '@/store/mutation-types'
import api from '@/tools/api.js'
import promise from '@/tools/promise'
// import { SUCCESS_STATUS } from '@/config/status'
const state = {
  tree: [],
  cover: {},
  saveData: {}
}

// mutations
const mutations = {
  [types.INTEGRAL_DOODS_TREE] (state, payload) {
    state.tree = payload
  },
  [types.INTEGRAL_CLASS_COVER] (state, payload) {
    state.cover = payload
  },
  [types.INTEGRAL_CLASS_SAVE_DATA] (state, payload) {
    state.saveData = payload
  }
}

// actions
const actions = {
  // 获取积分商品分类
  async goodsClassTree ({ commit }, payload) {
    let config = {loading: true, loadingText: '正在获取积分商品分类'}
    let res = await api('serverintegralmall/goods/GoodsCategory/goodsCateList', payload, config)
    commit(types.INTEGRAL_DOODS_TREE, res.res)
  },
  // 修改分类状态
  async changeCateStatus ({ commit }, payload) {
    let config = {loading: true, loadingText: '正在修改积分商品分类'}
    let res = await api('serverintegralmall/goods/GoodsCategory/changeCateStatus', payload, config)
    return promise(res)
  },
  // 删除分类
  async delCate ({ commit }, payload) {
    let config = {loading: true, loadingText: '正在删除积分商品分类'}
    let res = await api('serverintegralmall/goods/GoodsCategory/delCate', payload, config)
    return promise(res)
  },
  // 添加分类
  async addGoodsCate ({ commit }, payload) {
    let config = {loading: true, loadingText: '正在添加商品分类'}
    let res = await api('serverintegralmall/goods/GoodsCategory/addGoodsCate', payload, config)
    return promise(res)
  },
  // 编辑分类
  async editGoodsCate ({ commit }, payload) {
    let config = {loading: true, loadingText: '正在添加商品分类'}
    let res = await api('serverintegralmall/goods/GoodsCategory/editGoodsCate', payload, config)
    return promise(res)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
